package com.xizimall.portal.service.impl;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.xizimall.portal.pojo.SearchResult;
import com.xizimall.portal.service.SearchService;
import com.xizimall.common.pojo.XizimallResult;
import com.xizimall.common.utils.HttpClientUtil;
/**
 * 搜索服务
 * <p>Title: SearchServiceImpl</p>
 * <p>Description: </p>
 * <p>华南理工大学研究生</p> 
 * @author	李隆熹
 * @date	2018年4月25日上午11:36:52
 * @version 1.0
 */
@Service
public class SearchServiceImpl implements SearchService {
    
	@Value("${SEARCH_BASE_URL}")
	private String SEARCH_BASE_URL;
    
	@Override
	public SearchResult search(String queryString, int page) {
		//调用xizimall-search服务
		//查询参数
		Map<String, String> param=new HashMap<>();
		param.put("q", queryString);
		param.put("page", page+"");
		try {
			//调用服务
			String json=HttpClientUtil.doGet(SEARCH_BASE_URL, param);
			//把字符串转换成java对象
			XizimallResult xizimallResult=XizimallResult.formatToPojo(json, SearchResult.class);
			if(xizimallResult.getStatus()==200){
				SearchResult result=(SearchResult)xizimallResult.getData();
				return result;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
